﻿using Growatt.DuiHelpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace Growatt.Component.Cls
{
    public class TokenHelper
    {
        private const string TokenUrl = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal";
        private string accessToken;
        private DateTime tokenExpireTime; // 存储 token 过期时间

        public async Task<string> GetTenantAccessTokenAsync(string appId, string appSecret)
        {
            try
            {
                // 如果 token 已存在且未过期，则返回已有的 token
                if (!string.IsNullOrEmpty(accessToken) && DateTime.UtcNow < tokenExpireTime)
                {
                    return accessToken;
                }

                var client = new HttpClient();
                var requestBody = new
                {
                    app_id = appId,
                    app_secret = appSecret
                };

                var jsonBody = DuiHelperJson.ObjectToJson(requestBody);
                var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(TokenUrl, content);

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();
                    var responseData = DuiHelperJson.JsonToObject<TenantAccessTokenResponse>(responseString);

                    if (responseData.code == 0)
                    {
                        accessToken = responseData.tenant_access_token;
                        tokenExpireTime = DateTime.UtcNow.AddSeconds(responseData.expire); // 设置过期时间
                        Debug.WriteLine("获取 tenant_access_token 成功。");
                        return accessToken;
                    }
                    else
                    {
                        Debug.WriteLine($"获取失败: {responseData.code} - {responseData.msg}");
                    }
                }
                else
                {
                    Debug.WriteLine($"请求失败: {response.StatusCode} - {response.Content.ReadAsStringAsync().Result}");
                }
            }
            catch (Exception)
            {


            }

            return null;
        }
    }



    public class FeishuAPIHelper
    {
        public static FeishuAPIHelper feishuAPIHelperInstance => new FeishuAPIHelper();

        string FeishuAPIHelper_app_id = "cli_a7ea5c4ed83d900d";
        string FeishuAPIHelper_app_secret = "1kXpE9MgCVHLNOY8hdHJ4cLdbYRy7762";
        private readonly TokenHelper tokenHelper;

        public FeishuAPIHelper()
        {
            tokenHelper = new TokenHelper();
        }
        public async Task<String> GetTenantAccessToken()
        {
            var apiHelper = new FeishuAPIHelper();
            string accessToken = await apiHelper.tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);
            return accessToken;
        }

        /// <summary>
        // 获取消息
        /// </summary>
        /// <param name="container_id"></param>
        /// <param name="StartTime"></param>
        public async Task<bool> GetCallback(string container_id, string uer_id, string time)
        {
            //// 指定日期时间
            DateTime dateTime = System.DateTime.Now;
            //// 将日期时间转换为Unix时间戳（秒级）
            long unixTimestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;

            //string url = $"https://open.feishu.cn/open-apis/im/v1/messages?container_id={container_id}&container_id_type=chat&page_size=20&sort_type=ByCreateTimeDesc&start_time={time.ToString()}&end_time={unixTimestamp.ToString()}";
            string url = $"https://open.feishu.cn/open-apis/im/v1/messages?container_id={container_id}&container_id_type=chat&page_size=20&sort_type=ByCreateTimeDesc";
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);

            string authorizationToken = $"Bearer {accessToken}";

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", authorizationToken);

                HttpResponseMessage response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();
                    var rootObject = DuiHelperJson.JsonToObject<Rootobject>(content);
                    var containsUserSender = rootObject.data.items.FirstOrDefault(item => !string.IsNullOrEmpty(item.body.content)); //查找最新的一条信息是否是测试
                    if (containsUserSender != null && containsUserSender.body.content.Contains("{\"text\":\"收到\"}"))
                    {
                        return true;
                    }
                }
                else
                {
                    return false;
                }
            }
            return false;
        }
        /// <summary>
        /// 获取用户 ID
        /// </summary>
        /// <param name="emailsList"></param>
        /// <param name="mobilesList"></param>
        public async Task<List<string>> BatchGetUserIdAsync(List<string> emailsList, List<string> mobilesList)
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);
            if (string.IsNullOrEmpty(accessToken))
            {
                return null;
            }
            var client = new HttpClient();
            var requestBody = new
            {
                emails = emailsList,
                include_resigned = true,
                mobiles = mobilesList
            };


            var jsonBody = DuiHelperJson.ObjectToJson(requestBody);
            var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, "https://open.feishu.cn/open-apis/contact/v3/users/batch_get_id")
            {
                Content = content
            };
            requestMessage.Headers.Add("Authorization", $"Bearer {accessToken}");

            var response = await client.SendAsync(requestMessage);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("请求成功!");
                Debug.WriteLine("返回内容: ");
                var responseString = await response.Content.ReadAsStringAsync();
                Debug.WriteLine(responseString);
                ApiResponseUser apiResponse = DuiHelperJson.JsonToObject<ApiResponseUser>(responseString);
                return apiResponse.data.user_list.Select(o => o.user_id).ToList();
            }
            else
            {
                Debug.WriteLine($"请求失败! 状态码: {response.StatusCode}, 错误信息: {await response.Content.ReadAsStringAsync()}");
                return new List<string>();
            }
        }

        /// <summary>
        /// 查询参数实体类
        /// </summary>
        public class FetchUsersQueryParams
        {
            public string user_id_type { get; set; }
            public string department_id_type { get; set; }
            public string department_id { get; set; }
            public int page_size { get; set; }
            public string page_token { get; set; }
        }

        /// <summary>
        /// 获取用户 ID
        /// </summary>
        /// <param name="emailsList"></param>
        /// <param name="mobilesList"></param>
        public async Task BatchGetUserIdAsync2()
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);
            if (string.IsNullOrEmpty(accessToken))
            {
            }
            var client = new HttpClient();

            // 封装查询参数为实体对象
            var requestQueryParams = new FetchUsersQueryParams
            {
                user_id_type = "open_id",
                department_id_type = "open_department_id",
                department_id = "od-132f5beecdb34784f45ced813809259d",
                page_size = 2,
                page_token = null
            };

            List<string> userIds = new List<string>();



            do
            {
                string url =await BuildUrlWithQueryParamsAsync("https://open.feishu.cn/open-apis/contact/v3/users/find_by_department", requestQueryParams);
                var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
                requestMessage.Headers.Add("Authorization", $"Bearer {accessToken}");
                requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var response = await client.SendAsync(requestMessage);

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine("请求成功!");
                    Debug.WriteLine("返回内容: ");
                    var responseString = await response.Content.ReadAsStringAsync();
                    Debug.WriteLine(responseString);

                    ApiResponseUser apiResponse = JsonConvert.DeserializeObject<ApiResponseUser>(responseString);
                    userIds.AddRange(apiResponse.data.user_list.Select(o => o.user_id));

                    // 获取下一个 page_token
                    requestQueryParams.page_token = apiResponse.data.page_token; // 假设响应中包含 page_token
                }
                else
                {
                    Debug.WriteLine($"请求失败! 状态码: {response.StatusCode}, 错误信息: {await response.Content.ReadAsStringAsync()}");
                    break;
                }
            } while (!string.IsNullOrEmpty(requestQueryParams.page_token));

            Console.WriteLine("所有用户ID: ");
            foreach (var userId in userIds)
            {
                Console.WriteLine(userId);
            }
        }

        public class ApiResponseUser
        {
            public Data data { get; set; }
        }

        public class Data
        {
            public List<User> user_list { get; set; }
            public string page_token { get; set; } // 假设响应中包含 page_token
        }

        public class User
        {
            public string user_id { get; set; }
            // 其他可能需要的字段
        }

        /// <summary>
        /// 将对象转换为字典
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private Dictionary<string, string> ToDictionary(object obj)
        {
            var dictionary = new Dictionary<string, string>();
            foreach (var property in obj.GetType().GetProperties())
            {
                if (property.GetValue(obj, null) != null)
                {
                    dictionary[property.Name] = property.GetValue(obj, null).ToString();
                }
            }
            return dictionary;
        }
        /// <summary>
        /// 构建带有查询参数的URL
        /// </summary>
        /// <param name="baseUrl"></param>
        /// <param name="queryParams"></param>
        /// <returns></returns>
        private async Task<string> BuildUrlWithQueryParamsAsync(string baseUrl, object queryParams)
        {
            var queryString = new FormUrlEncodedContent(ToDictionary(queryParams));
            var fullUrl = $"{baseUrl}?{await queryString.ReadAsStringAsync()}";
            return fullUrl;
        }
        public async Task<string> SendMessageAsync(string receiveId, string content, Action<ApiResponseMessage> callback)
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);

            var client = new HttpClient();
            var requestBody = new
            {
                content = DuiHelperJson.ObjectToJson(new { text = content }),
                msg_type = "text",
                receive_id = receiveId
            };

            var jsonBody = DuiHelperJson.ObjectToJson(requestBody);
            var contentToSend = new StringContent(jsonBody, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
            var url = "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id";
            // 创建一个 HttpRequestMessage 并设置为 Patch 方法
            var request = new HttpRequestMessage(new HttpMethod("POST"), url)
            {
                Content = contentToSend
            };

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("请求成功!");
                Debug.WriteLine("返回内容: ");
                var responseString = await response.Content.ReadAsStringAsync();
                Debug.WriteLine(responseString);
                ApiResponseMessage apiResponse = DuiHelperJson.JsonToObject<ApiResponseMessage>(responseString);
                callback?.Invoke(apiResponse);
                return apiResponse.data.message_id;
            }
            else
            {
                Debug.WriteLine($"请求失败! 状态码: {response.StatusCode}, 错误信息: {await response.Content.ReadAsStringAsync()}");
                return string.Empty;
            }
        }

        /// <summary>
        /// 电话加急
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="userIdList"></param>
        /// <param name="userIdType"></param>
        /// <returns></returns>
        public async Task<SendUrgentPhoneResponse> SendUrgentPhoneAsync(string messageId, List<string> userIdList, string userIdType = "open_id")
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);
            string url = $"https://open.feishu.cn/open-apis/im/v1/messages/{messageId}/urgent_phone?user_id_type={userIdType}";

            var client = new HttpClient();
            var payload = new
            {
                user_id_list = userIdList
            };

            var jsonBody = DuiHelperJson.ObjectToJson(payload);
            var contentToSend = new StringContent(jsonBody, Encoding.UTF8, "application/json");
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);

            // 创建一个 HttpRequestMessage 并设置为 Patch 方法
            var request = new HttpRequestMessage(new HttpMethod("PATCH"), url)
            {
                Content = contentToSend
            };

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("紧急电话请求已成功发送。");
                Debug.WriteLine("响应内容: " + await response.Content.ReadAsStringAsync());
                // 反序列化 JSON 字符串
                SendUrgentPhoneResponse apiResponse = DuiHelperJson.JsonToObject<SendUrgentPhoneResponse>(await response.Content.ReadAsStringAsync());
                return apiResponse;
            }
            else
            {
                Debug.WriteLine($"请求失败: {response.StatusCode} - {await response.Content.ReadAsStringAsync()}");
            }
            return null;
        }


        /// <summary>
        /// 短信加急
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="userIdList"></param>
        /// <param name="userIdType"></param>
        /// <returns></returns>
        public async Task<SendUrgentPhoneResponse> SendUrgent_smsAsync(string messageId, List<string> userIdList, string userIdType = "open_id")
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);
            string url = $"https://open.feishu.cn/open-apis/im/v1/messages/{messageId}/urgent_sms?user_id_type={userIdType}";

            var client = new HttpClient();
            var payload = new
            {
                user_id_list = userIdList
            };

            var jsonBody = DuiHelperJson.ObjectToJson(payload);
            var contentToSend = new StringContent(jsonBody, Encoding.UTF8, "application/json");
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
            // 创建一个 HttpRequestMessage 并设置为 Patch 方法
            var request = new HttpRequestMessage(new HttpMethod("PATCH"), url)
            {
                Content = contentToSend
            };

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("紧急短信请求已成功发送。");
                Debug.WriteLine("响应内容: " + await response.Content.ReadAsStringAsync());
                // 反序列化 JSON 字符串
                SendUrgentPhoneResponse apiResponse = DuiHelperJson.JsonToObject<SendUrgentPhoneResponse>(await response.Content.ReadAsStringAsync());
                return apiResponse;
            }
            else
            {
                Debug.WriteLine($"请求失败: {response.StatusCode} - {await response.Content.ReadAsStringAsync()}");
            }
            return null;
        }

        /// <summary>
        /// 发送应用加急
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="userIdList"></param>
        /// <param name="userIdType"></param>
        /// <returns></returns>
        public async Task<SendUrgentPhoneResponse> SendUrgent_MessAsync(string messageId, List<string> userIdList, string userIdType = "open_id")
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);
            string url = $"https://open.feishu.cn/open-apis/im/v1/messages/{messageId}/urgent_app?user_id_type={userIdType}";

            var client = new HttpClient();
            var payload = new
            {
                user_id_list = userIdList
            };

            var jsonBody = DuiHelperJson.ObjectToJson(payload);
            var contentToSend = new StringContent(jsonBody, Encoding.UTF8, "application/json");
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);

            // 创建一个 HttpRequestMessage 并设置为 Patch 方法
            var request = new HttpRequestMessage(new HttpMethod("PATCH"), url)
            {
                Content = contentToSend
            };

            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("紧急应用请求已成功发送。");
                Debug.WriteLine("响应内容: " + await response.Content.ReadAsStringAsync());
                // 反序列化 JSON 字符串
                SendUrgentPhoneResponse apiResponse = DuiHelperJson.JsonToObject<SendUrgentPhoneResponse>(await response.Content.ReadAsStringAsync());
                return apiResponse;
            }
            else
            {
                Debug.WriteLine($"请求失败: {response.StatusCode} - {await response.Content.ReadAsStringAsync()}");
            }
            return null;
        }



        public async Task<string> GetReadUsersAsync(string messageId)
        {
            string accessToken = await tokenHelper.GetTenantAccessTokenAsync(FeishuAPIHelper_app_id, FeishuAPIHelper_app_secret);

            using (var client = new HttpClient())
            {
                client.Timeout = TimeSpan.FromMilliseconds(-1); // 设置超时时间，-1表示无限超时
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                var url = $"https://open.feishu.cn/open-apis/im/v1/messages/{messageId}/read_users?user_id_type=open_id";

                var response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();
                    var apiResponse = DuiHelperJson.JsonToObject<RootobjectSendMessageResponse>(await response.Content.ReadAsStringAsync());

                    if (apiResponse.data.items?.Count() > 0)
                    {
                        return responseString;
                    }
                }
                else
                {
                    Debug.WriteLine($"请求失败! 状态码: {response.StatusCode}, 错误信息: {await response.Content.ReadAsStringAsync()}");
                    return string.Empty;
                }
                return string.Empty;
            }
        }

    }

    public class FeishuAPIHelperUsage
    {

        public static FeishuAPIHelperUsage feishuAPIHelperUsageInstance => new FeishuAPIHelperUsage();
        public async Task<string> SendUrgentPhoneUrl(List<string> emailsList, String sendString, Action<ApiResponseMessage> callback)
        {
            string isSuccess = string.Empty;
            var list = await FeishuAPIHelper.feishuAPIHelperInstance.BatchGetUserIdAsync(emailsList, new List<string>());
            if (list?.Count > 0)
            {

                var message_id = await FeishuAPIHelper.feishuAPIHelperInstance.SendMessageAsync(list[0], sendString, (o) => { callback.Invoke(o); });
                if (!string.IsNullOrEmpty(message_id))
                {
                    SendUrgentPhoneResponse SendUrgentPhone_result = await FeishuAPIHelper.feishuAPIHelperInstance.SendUrgentPhoneAsync(message_id, new List<string>() { list[0] });
                    if (SendUrgentPhone_result?.data?.invalid_user_id_list?.Count == 0)
                        isSuccess = message_id;

                }
            }
            return isSuccess;
        }

        /// <summary>
        /// 发送应用加急消息
        /// </summary>
        /// <param name="emailsList"></param>
        /// <param name="sendString"></param>
        /// <returns></returns>
        public async Task<string> SendUrgentMessageUrl(List<string> emailsList, String sendString, Action<ApiResponseMessage> callback)
        {
            string isSuccess = string.Empty;
            var list = await FeishuAPIHelper.feishuAPIHelperInstance.BatchGetUserIdAsync(emailsList, new List<string>());
            if (list?.Count > 0)
            {

                var message_id = await FeishuAPIHelper.feishuAPIHelperInstance.SendMessageAsync(list[0], sendString, (o) => { callback.Invoke(o); });
                if (!string.IsNullOrEmpty(message_id))
                {
                    SendUrgentPhoneResponse SendUrgentPhone_result = await FeishuAPIHelper.feishuAPIHelperInstance.SendUrgent_MessAsync(message_id, new List<string>() { list[0] });
                    if (SendUrgentPhone_result?.data?.invalid_user_id_list?.Count == 0)
                        isSuccess = message_id;

                }
            }
            return isSuccess;
        }

        public async Task<string> SendMessageUrl(List<string> emailsList, String sendString, Action<ApiResponseMessage> callback)
        {
            string isSuccess = string.Empty;
            var list = await FeishuAPIHelper.feishuAPIHelperInstance.BatchGetUserIdAsync(emailsList, new List<string>());
            if (list?.Count > 0)
            {

                var message_id = await
                    FeishuAPIHelper.feishuAPIHelperInstance.SendMessageAsync(list[0], sendString, (o) => { callback?.Invoke(o); });
                if (!string.IsNullOrEmpty(message_id))
                    isSuccess = message_id;
            }
            return isSuccess;
        }


        public async Task<string> SendMessageCallbackUrlAsync(string messageId)
        {

            return await FeishuAPIHelper.feishuAPIHelperInstance.GetReadUsersAsync(messageId);
        }

        public async Task<bool> GetCallbackAsync(string container_id, string uer_id, string time)
        {
            return await FeishuAPIHelper.feishuAPIHelperInstance.GetCallback(container_id, uer_id, time);
        }
    }

    // 用于反序列化响应的类
    public class TenantAccessTokenResponse
    {
        public int code { get; set; }
        public string msg { get; set; }
        public string tenant_access_token { get; set; }
        public int expire { get; set; }
    }



    public class RootobjectSendMessageResponse
    {
        public int code { get; set; }
        public DataSendMessageResponse data { get; set; }
        public string msg { get; set; }
    }

    public class DataSendMessageResponse
    {
        public bool has_more { get; set; }
        public ItemSendMessageResponse[] items { get; set; }
    }

    public class ItemSendMessageResponse
    {
        public string tenant_key { get; set; }
        public string timestamp { get; set; }
        public string user_id { get; set; }
        public string user_id_type { get; set; }
    }



    #region 获取ID返回
    public class ApiResponseUser
    {
        public int code { get; set; }
        public Data data { get; set; }
        public string msg { get; set; }
    }

    public class Data
    {
        public List<UserInformation> user_list { get; set; }
    }

    public class UserInformation
    {
        public string email { get; set; }
        public StatusUser status { get; set; }
        public string user_id { get; set; }
    }

    public class StatusUser
    {
        public bool is_activated { get; set; }
        public bool is_exited { get; set; }
        public bool is_frozen { get; set; }
        public bool is_resigned { get; set; }
        public bool is_unjoin { get; set; }
    }
    #endregion

    #region 发送消息返回
    public class ApiResponseMessage
    {
        public int code { get; set; }
        public MessageData data { get; set; }
        public string msg { get; set; }
    }

    public class MessageData
    {
        public MessageBody body { get; set; }
        public string chat_id { get; set; }
        public string create_time { get; set; }
        public bool deleted { get; set; }
        public string message_id { get; set; }
        public string msg_type { get; set; }
        public SenderInfo sender { get; set; }
        public string update_time { get; set; }
        public bool updated { get; set; }
    }

    public class MessageBody
    {
        public string content { get; set; }
    }

    public class SenderInfo
    {
        public string id { get; set; }
        public string id_type { get; set; }
        public string sender_type { get; set; }
        public string tenant_key { get; set; }
    }

    #endregion

    #region 发送紧急电话
    public class SendUrgentPhoneResponse
    {
        public int code { get; set; }
        public SendUrgentPhoneData data { get; set; }
        public string msg { get; set; }
    }

    public class SendUrgentPhoneData
    {
        public List<string> invalid_user_id_list { get; set; }
    }
    #endregion




    public class Rootobject
    {
        public int code { get; set; }
        public DataMessageReceived data { get; set; }
        public string msg { get; set; }
    }

    public class DataMessageReceived
    {
        public bool has_more { get; set; }
        public ItemMessageReceived[] items { get; set; }
        public string page_token { get; set; }
    }

    public class ItemMessageReceived
    {
        public Body body { get; set; }
        public string chat_id { get; set; }
        public string create_time { get; set; }
        public bool deleted { get; set; }
        public string message_id { get; set; }
        public string msg_type { get; set; }
        public Sender sender { get; set; }
        public string update_time { get; set; }
        public bool updated { get; set; }
    }

    public class Body
    {
        public string content { get; set; }
    }

    public class Sender
    {
        public string id { get; set; }
        public string id_type { get; set; }
        public string sender_type { get; set; }
        public string tenant_key { get; set; }
    }



}
